package bma.common.netty;

import org.jboss.netty.channel.ChannelHandler;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.channel.Channels;

import bma.common.langutil.pipeline.CommonPipelineBuilder;

public class ChannelPipelineFactory4Builder implements ChannelPipelineFactory {

	protected CommonPipelineBuilder<ChannelHandler> builder;

	public ChannelPipelineFactory4Builder() {
		super();
	}

	public ChannelPipelineFactory4Builder(
			CommonPipelineBuilder<ChannelHandler> builder) {
		super();
		this.builder = builder;
	}

	public CommonPipelineBuilder<ChannelHandler> getBuilder() {
		return builder;
	}

	public void setBuilder(CommonPipelineBuilder<ChannelHandler> builder) {
		this.builder = builder;
	}

	@Override
	public ChannelPipeline getPipeline() throws Exception {
		if (builder == null)
			throw new NullPointerException("builder");
		ChannelPipeline r = Channels.pipeline();
		if (builder != null) {
			builder.buildPipeline(new NettyChannelPipeline(r));
		}
		return r;
	}

}
